<template>
	<view class="container">
		<view class="head">
			<image v-if="orderInfo.pay_status == 1" src="@/static/pay@success.png"></image>
			<image v-else src="@/static/pay@error.png"></image>
		</view>
		<view class="content">
			<view class="title" v-if="orderInfo.pay_status == 1">订单支付失败</view>
			<view class="title" v-else>订单支付成功</view>
			<view class="line"></view>
			<view class="item">
				<view>订单号</view>
				<view>{{ orderInfo.order_no }}</view>
			</view>
			<view class="item">
				<view>下单时间</view>
				<view>{{ orderInfo.create_time }}</view>
			</view>
			<view class="item">
				<view>支付方式</view><!-- 暂未支付 -->
				<view>暂未支付</view>
			</view>
			<view class="item">
				<view>支付金额</view>
				<view>{{ orderInfo.pay_price }}</view>
			</view>
			<view class="item" v-if="orderInfo.pay_status == 0">
				<view>失败原因</view>
				<!-- 订单状态 0未付款 1已付款/待发货 2已发货/待收货 3已收货/待评价/已完成 -1退款/退款退货申请 -2已退款/已退款退货 -3拒绝 -4取消交易 -5关闭交易 -->
				<view v-if="orderInfo.order_status == -4">取消支付</view>
				<view v-else>未支付</view>
			</view>
			<view class="line"></view>
			<view class="btn" @click="toRefresh()">刷新支付状态</view>
			<view class="btn" @click="toPay()" v-if="orderInfo.pay_status == 0">重新支付</view>
			<view class="btn1" @click="toHome()">返回首页</view>
		</view>
		
	</view>
</template>

<script>
	import { Order } from '@/utils/model/order-model.js';
	var order = new Order();
	
	export default {
		data() {
			return {
				orderId: 0,
				orderInfo: {}
			}
		},
		onLoad(options) {
			// 记录订单ID
			this.orderId = Number(options.id)
			this.getDetail()
		},
		
		methods: {
			toRefresh(){
				this.getDetail()
			},
			toHome(){
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			toPay(){
				uni.navigateTo({
					url: '/pages/order/list'
				})
			},
			getDetail() {
				uni.showLoading({
					title: '正在加载中'
				})
				const that = this; 
				order.getDetail(that.orderId).then((res) => {
					console.log(res)
					console.log('mmmmmmmmmmmmmmmmmmmmmmmmm')
					uni.hideLoading();
					if(res.code == 1){
						that.orderInfo = res.data.detail
					}else{
						uni.showToast({
							title: res.msg
						})
					}
				}).catch((err) => {
					console.log(err)
					console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
				})
			},
		}
	}
</script>

<style>
	page{
		background-color: #F5F5F5;
	}
</style>
 
<style scoped lang="scss">
	@import '~@/pages/order/result.scss';
</style>